perm filename PUPSDF.C[11,HE] blob sn#688208 filedate 1982-12-06 generic text, type T, neo UTF8
/* LINTLIBRARY */
/*
 * pupsetdfilt.c
 *
 * Builds and sets a packet filter for a pup channel.
 * This sets a filter according to some default conventions:
 *	(1) Always filters on destination socket
 *	(2) Filters on destination host if PCM_BROADCAST is not set.
 *	(3) THIS SHOULD BE DONE: accept 0 or dest net if PCM_BROADCAST not set.
 *
 * Jeffrey Mogul @ Stanford	29-January-1981
 *
 */

#ifdef VAX
#define offset(b,a) ( (int)&(b->a) - (int)(b) )

#include <puplib.h>
#include <pupconstants.h>
#include <pupstatus.h>
#include <puppacket.h>

pupsetdfilt(Pchan,priority)
struct PupChan *Pchan;		/* open pup channel */
uchar	priority;		/* filter priority */
{	/* */
	register struct enfilter *ef;	/* used as a temporary */
	register struct PupPacket *pp;	/* used as a placeholder */
	register struct EnPacket *ep;	/* used as a placeholder */
	int	efterms;	/* terms in the filter */

	/*
	 * Here we would switch on Pchan->transport to
	 * decide what sort of filter mechanism to build;
	 * currently, the only choice is an enfilter.
	 */
	
	ef = &(Pchan->filter.en);	/* get address of filter */

	efinit(ef,priority);	/* init the filter with the given priority */

	/* always insure that the ethernet packet type is Pup */

	efwdinsert(ef,offset(ep,PacketType),PUP);

	/* always filter on destination socket */
	eflginsert(ef,ENPACKOVER+offset(pp,PupDst.pk_FSocket),
			makelong(Pchan->SrcPort.socket));
	
	efterms = 2;	/* 1 from PacketType, 1 from PupDst.pk_FSocket */

	/* if not a broadcast reception port, filter on DstHost */
	if ( (Pchan->mode&PCM_BROADCAST) == 0) {
		efterms++;
		efchinsert(ef,ENPACKOVER+offset(pp,PupDst.pk_Host),
				Pchan->SrcPort.host);
		}

	/*
	 * between each term in the filter, include an AND operation.
	 */
	for (; efterms > 1 ; efterms--) {
		if (efAND(ef) != OK) return(FILTERTOOBIG);
		}

	/* filter is built, insure that it is set onto channel */
	ensetfilt(Pchan->ifid, &Pchan->filter.en);

	return(OK);
}

#endif VAX

#ifdef MC68000

#include <puplib.h>
#include <pupconstants.h>
#include <pupstatus.h>
#include <puppacket.h>

pupsetdfilt(Pchan,priority)
struct PupChan *Pchan;		/* open pup channel */
uchar	priority;		/* filter priority */
{	/* */
	register struct enfilter *ef;	/* used as a temporary */

	/*
	 * Here we would switch on Pchan->transport to
	 * decide what sort of filter mechanism to build;
	 * currently, the only choice is an enfilter.
	 */
	
	ef = &(Pchan->filter.en);	/* get address of filter */

	/* always insure that the ethernet packet type is Pup, and
	 * to right destination socket */
	ef->mask = ENPTYPE|DSTSOCK;		/* indicate in mask */
	ef->enptype = PUP;		/* remember the packet type */
	ef->dstsock = Pchan->SrcPort.socket;	/* and socket */

	/* if not a broadcast reception port, filter on DstHost */
	if ( (Pchan->mode&PCM_BROADCAST) == 0) {
		ef->mask |= DSTHOST;	/* indicate in mask */
		ef->dsthost = Pchan->SrcPort.host;
		}

	return(OK);
}

#endif MC68000